import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login'
import Master from '../views/Master'
import Users from "../views/system/Users";
import Role from "../views/system/Role";
import Menu from "../views/system/Menu";
import Log from "../views/system/Log";


import Customer from '../views/Customer'
import Mumber from "../views/client/Mumber";
import Level from "../views/client/Level";
import Integration from "../views/client/Integration";
import Coupon from "../views/client/Coupon";
import CouRecord from "../views/client/CouRecord";

import AdverManage from "../views/marketing/AdverManage";
import AdverPosition from "../views/marketing/AdverPosition";
import CustoIssues from "../views/marketing/CustoIssues";
import MaintainShop from "../views/safeguard/MaintainShop";
import MainTainRecord from "../views/safeguard/MainTainRecord";

import TJOrder from "../views/statistics/TJOrder";
import TJLog from "../views/statistics/TJLog";
import Brand from "../views/lease/Brand";
import Car from "../views/lease/Car";
import Comment from "../views/lease/Comment";
import Config from "../views/lease/Config";
import Shop from "../views/lease/Shop";
import Type from "../views/lease/Type";


Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect:'/login'
  },
  {
    path: '/login',
    name: 'Login',
    component: Login
  },
  {
    path: '/master',
    name: 'Master',
    component: Master,
    children:[
      {
        path: '/system/users',
        name: 'Users',
        component: Users
      },
      {
        path: '/system/role',
        name: 'Role',
        component: Role
      },
      {
        path: '/system/menu',
        name: 'Menu',
        component: Menu
      },
      {
        path: '/system/log',
        name: 'Log',
        component: Log
      },
      // 营销的三个路径
      // 广告管理路径
      {
        path: '/marketing/adverManage',
        name: 'AdverManage',
        component: AdverManage
      },
      //广告位置路径
      {
        path: '/marketing/adverPosition',
        name: 'AdverPosition',
        component: AdverPosition
      },
      //客服问答的路径
      {
        path: '/marketing/custoIssues',
        name: 'CustoIssues',
        component: CustoIssues
      },
      {
        path: '/lease/carBrand',
        name: 'Brand',
        component: Brand
      },
      {
        path: '/lease/car',
        name: 'Car',
        component: Car
      },
      {
        path: '/lease/carComment',
        name: 'Comment',
        component: Comment
      },
      {
        path: '/lease/carConfig',
        name: 'Config',
        component: Config
      },
      {
        path: '/lease/carShop',
        name: 'Shop',
        component: Shop
      },
      {
        path: '/lease/carType',
        name: 'Type',
        component: Type
      }
    ]
  },

  {// 客户管理
    path: '/customer',
    name: 'Customer',
    component: Customer,
    children:[
      { //会员管理
        path: '/client/mumber',
        name: 'Mumber',
        component: Mumber
      },
      {// 会员等级
        path: '/client/level',
        name: 'Level',
        component: Level
      },
      {// 积分记录
        path: '/client/integration',
        name: 'Integration',
        component: Integration
      },
      {// 会员优惠券
        path: '/client/coupon',
        name: 'Coupon',
        component: Coupon
      },
      {// 优惠券记录
        path: '/client/couRecord',
        name: 'CouRecord',
        component: CouRecord

      },
      {
        path: '/safeguard/MaintainShop',
        name: 'MaintainShop',
        component: MaintainShop
      },
      {
        path: '/safeguard/MainTainRecord',
        name: 'MainTainRecord',
        component: MainTainRecord
      },
      {
        path: '/statistics/TJOrder',
        name: 'TJOrder',
        component: TJOrder
      },
      {
        path: '/statistics/TJLog',
        name: 'TJLog',
        component: TJLog
      },
    ]
  },



]

const router = new VueRouter({
  routes
})
//路由守卫to:表示跳转的路径   from:从哪跳转  next():放行
//在前端判断请求路径是否登录
router.beforeEach((to,from,next)=>{
  //1. to是login应该放行
  var path=to.path;
  if (path==='/login'){
    return next();
  }
  //2.判断是否登录
  var token=sessionStorage.getItem("token");
  if (token){
    return next();
  }
  //3.跳转到登录
  next("/login");
})

export default router
